package vip.xiaonuo.smzq.modular.lifecycle.controller.entity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Date;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.smzq.modular.lifecycle.constant.WebResultStatusConstant;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclCb06Kc;
import vip.xiaonuo.smzq.modular.lifecycle.mapper.entity.KclCb06KcMapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.ResultWrapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.WebResult;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.KclCb06KcService;

/**
 * <p>
 * 矿产 前端控制器
 * </p>
 *
 * @author 于彦飞
 * @since 2024-03-25
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"矿产模块"})
@RestController
@RequestMapping("/kclCb06Kc" )

public class KclCb06KcController {
    @Autowired
    private KclCb06KcService kclCb06KcService;
    @Autowired
    private KclCb06KcMapper kclCb06KcMapper;
    @Resource
    ResultWrapper resultWrapper;

    @ApiOperation(value = "查询所有矿产接口", notes = "查询所有矿产接口")
    @PostMapping(value = "/list")
    public WebResult queryKclCb06KcList(@RequestBody KclCb06Kc kclCb06Kc) {

        return resultWrapper.getSuccessWebResult(kclCb06KcService.queryKclCb06KcList(kclCb06Kc));
    }

    @ApiOperation(value = "分页查询矿产接口", notes = "分页查询矿产接口")
    @PostMapping(value = "/list/page")
    public WebResult queryKclCb06KcListPage(@RequestBody KclCb06Kc kclCb06Kc) {

        return resultWrapper.getSuccessWebResult(kclCb06KcService.queryKclCb06KcListPage(kclCb06Kc));
    }



    @ApiOperation(value = "根据id查询矿产接口", notes = "根据id查询矿产接口")
    @GetMapping(value = "byId/{id}")
    public WebResult queryKclCb06KcById(@PathVariable("id") String id) {

        KclCb06Kc entity  = kclCb06KcService.getById(id);
//        DictConvertUtil.convertToDictionary(entity,null);

        return resultWrapper.getSuccessWebResult(entity);
    }

    @ApiOperation(value = "根据id删除矿产接口", notes = "根据id删除矿产接口")
    @PostMapping(value = "d/{id}")
    public WebResult delById(@PathVariable("id")String id) {
        return resultWrapper.getWebResultByDelSuccess(kclCb06KcService.delKclCb06Kc(id));
    }

    @ApiOperation(value = "根据id批量删除矿产接口", notes = "根据id批量删除矿产接口")
    @PostMapping(value = "/d/batch")
    public WebResult delById(@RequestBody List<String> ids) {
        return resultWrapper.getWebResultByDelSuccess(kclCb06KcService.delKclCb06KcBatch(ids));
    }

    @ApiOperation(value = "新增矿产接口", notes = "新增矿产接口")
    @PostMapping(value = "/save")
    public WebResult save(@RequestBody KclCb06Kc kclCb06Kc) {
        boolean isSuccess = kclCb06KcService.save(kclCb06Kc);
        if(isSuccess){
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, kclCb06Kc.getPkid());
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "批量新增矿产接口", notes = "批量矿产接口")
    @PostMapping(value = "save/batch")
    public WebResult saveBath(@RequestBody List<KclCb06Kc> kclCb06Kcs) {
        boolean isSuccess = kclCb06KcService.saveBatch(kclCb06Kcs);
        if(isSuccess){
            List<String> ids = kclCb06Kcs.stream().map(ele->ele.getPkid()).collect(Collectors.toList());
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, ids);
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "更新用户接口", notes = "id必须有值")
    @PostMapping(value = "/update")
    public WebResult update(@RequestBody KclCb06Kc kclCb06Kc) {
        return resultWrapper.getWebResultByEditSuccess(kclCb06KcService.updateById(kclCb06Kc));
    }
    @ApiOperation(value = "批量更新矿产接口", notes = "id必须有值")
    @PostMapping(value = "/update/batch")
    public WebResult updateBatch(@RequestBody List<KclCb06Kc> kclCb06Kcs) {
        return resultWrapper.getWebResultByCreateSuccess(kclCb06KcService.updateBatchById(kclCb06Kcs));
    }
    @ApiOperation(value = "新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate")
    public WebResult saveOrUpdate(@RequestBody KclCb06Kc kclCb06Kc) {

        return resultWrapper.getSuccessWebResult(kclCb06KcService.saveOrUpdate(kclCb06Kc));
    }
    @ApiOperation(value = "批量新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate/batch")
    public WebResult saveOrUpdate(@RequestBody List<KclCb06Kc> kclCb06Kcs) {

        return resultWrapper.getSuccessWebResult(kclCb06KcService.saveOrUpdateBatch(kclCb06Kcs));
    }

}
